var arr = [];   //存所以数据
var count = 5 //一页多少条数据
var page = 1 //当前的页数
var n;
var user = JSON.parse(localStorage.getItem
$.ajax({
    url: '/api/notice/getnotice',
    success: function (res) {
        console.log(res)
        if (res.data.length) {
            arr = res.data;
            createPage();
            getCon();
        }
    }
})
function getCon() {
    $('.gonggao1 ul').html('');
    $.each(arr.slice((page - 1) * count, page * count), function (i, v) {
        $('.gonggao1 ul').append(
            ' <li><span>' + v.mytime + '</span>\
                    <p class="p1">'+ v.title + '</p>\
                    <p class="p2">'+ v.content + '1</p>\
                </li>'
        )
    })
}
$('#nav2').on('click', 'li', function () {
    page = $(this).text();
    getCon();
})
// 创建页码

function createPage() {
    var n = Math.ceil(arr.length / count);
    $('#nav2 .diyebiao').remove();
    for (var i = 1; i <= n; i++) {
        $('.yeshu').before($('<li class="diyebiao"><a href="#">' + i + '</a></li>'));
    }

}
//切换账号
$('#qiehuanzhanghao').on('click',function(){
    window.location.href='/wb258-2/page/HomePage.html'
})
// 退出
$('#guanbichuangko').on('click',function(){
    closePage();
    // window.location.href="https://blog.csdn.net/kuangfengbuyi/article/details/52052301"
     
})
function closePage(){
    if(navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Chrome") != -1){
        window.location.href = "about:blank";
        window.close();
    }else{
        window.opener = null;
        window.open("", "_self");
        window.close();
    }
}
// 添加公告
// 当点击添加公告的时候
// $('.tiangonggao').on('click',function(){
//     $.ajax({
//         url:'/api/notice/addnotice',
//         data:{
//             content:$('.gonggaoneirong').val(),
//             title:$('.gonggaobiaoti').val(),
//             userId:
//         }
//     })
// })